package de.klingbeil.hhc.client.widget;

import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;

import de.klingbeil.hhc.client.WebAppResource;

public class BasicHeader {
	protected static final int DEFAULT_LOWER_BAR_HEIGHT = 36;
	protected static final int DEFAULT_UPPER_BAR_HEIGHT = 80;
	private LayoutContainer contentPanel;
	private LayoutContainer rootPanel;
	private int lowerBarHeight;
	private int upperBarHeight;
	private Image logoImage;

	public BasicHeader() {
		this(DEFAULT_UPPER_BAR_HEIGHT, DEFAULT_LOWER_BAR_HEIGHT);
	}

	public BasicHeader(int upperBarHeight, int lowerBarHeight) {
		this.upperBarHeight = upperBarHeight;
		this.lowerBarHeight = lowerBarHeight;
		createPanel();
	}

	private void createPanel() {
		rootPanel = new LayoutContainer(new RowLayout(Orientation.VERTICAL));
		rootPanel.add(contentPanel = createHorizontalContentPanel(),
				new RowData(1.0, upperBarHeight));
		rootPanel.add(createBar(), new RowData(1.0, lowerBarHeight));
	}

	private LayoutContainer createHorizontalContentPanel() {
		LayoutContainer horizontalPanel = new LayoutContainer(new RowLayout(
				Orientation.HORIZONTAL));
		horizontalPanel.setStyleName("hhc-header");
		logoImage = createLogo();
		horizontalPanel.add(logoImage, createLogoLayoutData());
		return horizontalPanel;
	}

	private static RowData createLogoLayoutData() {
		RowData layoutData = new RowData();
		layoutData.setMargins(new Margins(37, 0, 0, 4));
		return layoutData;
	}

	private static Widget createBar() {
		Widget result = new LayoutContainer();
		result.setStyleName("hhc-header-bar");
		return result;
	}

	private static Image createLogo() {
		Image result = new Image(WebAppResource.INSTANCE.logo());
		result.setStyleName("hsx-logo");
		return result;
	}

	public Widget getWidget() {
		return rootPanel;
	}

	protected LayoutContainer getContentPanel() {
		return contentPanel;
	}

	public int getHeight() {
		return upperBarHeight + lowerBarHeight;
	}

	protected Image getLogoImage() {
		return logoImage;
	}

}
